package security

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"project-deploy-service/redis"
)

type jwtAuthenticationTokenFilter struct{}

var JwtAuthenticationTokenFilter jwtAuthenticationTokenFilter

func (f *jwtAuthenticationTokenFilter) DoFilterInternal(c *gin.Context) {
	token := c.GetHeader("Authorization")
	user := redis.TokenService.GetLoginUser(token)
	if user != nil {
		c.Next()
	} else {
		c.String(http.StatusUnauthorized, "用户未认证!")
		c.Abort()
	}
}
